package com.copa.module.goods.controller;

import com.copa.domain.ResponseDto;
import com.copa.module.goods.domain.dto.GoodsInfoDetailDto;
import com.copa.module.goods.domain.dto.IndexGoodsListDto;
import com.copa.module.goods.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author copa
 * @createDate 2021-01-14 11:54
 * @function
 */
@RestController
@Api(tags = {"商品接口"})
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("/goods/indexList")
    @ApiOperation(value = "首页热门商品列表")
    public ResponseDto<List<IndexGoodsListDto>> indexList() {
        return goodsService.indexList();
    }

    @GetMapping("/goods/categoryGoods")
    @ApiOperation(value = "根据类目id查商品列表")
    public ResponseDto<List<IndexGoodsListDto>> categoryGoods(@ApiParam("类目id") Long categoryId) {
        return goodsService.categoryGoods(categoryId);
    }

    @GetMapping("/goods/detail")
    @ApiOperation(value = "根据商品id查商品列表")
    public ResponseDto<GoodsInfoDetailDto> detail(@ApiParam("商品id") Long goodsId) {
        return goodsService.detail(goodsId);
    }

    @GetMapping("/goods/search")
    @ApiOperation(value = "根据关键字查商品")
    public ResponseDto<List<IndexGoodsListDto>> search(@ApiParam("商品id") @RequestParam(required = false) String goodsName) {
        return goodsService.search(goodsName);
    }
}
